//------------------------------------------------------------------------------
// <copyright file="WindowPrint.xaml.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.IO;
using System.Windows;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using DotBeer.Business.Entities;
using DotBeer.Data.Properties;
using DAnton.Utilities.Extensions;

namespace DotBeer.UI.WPFClient.Views
{
    /// <summary>
    /// Interaction logic for WindowPrint.xaml
    /// </summary>
    public partial class WindowPrint : Window
    {
        #region private members

        HeroPrintingSettings heroPrintingSettings;

        #endregion

        #region constructors

        public WindowPrint(HeroPrintingSettings heroPrintingSettings)
        {
            InitializeComponent();

            this.heroPrintingSettings = heroPrintingSettings;
        }

        #endregion

        #region private methods

        private void DockPanel_Loaded(object sender, RoutedEventArgs e)
        {
            string tempFileName = System.IO.Path.GetTempFileName();
            File.Delete(tempFileName);

            using (XpsDocument xpsDoc = new XpsDocument(tempFileName, FileAccess.ReadWrite))
            {
                XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
                //writer.Write(new HeroPaginator(this.hero));
                writer.Write(new HeroPaginator(this.heroPrintingSettings));

                this.DocumentViewer.Document = xpsDoc.GetFixedDocumentSequence();
            }

            this.Title = String.Format("{0} - print - DotBeer", this.heroPrintingSettings.Hero.Name);
            //this.Title = String.Format("{0} - print - DotBeer", this.hero.Name);
        }

        #endregion
    }
}
